//
//  AppDelegate.m
//  EncodeTest
//
//  Created by wangrui on 13-11-6.
//  Copyright (c) 2013年 PPS. All rights reserved.
//

#import "AppDelegate.h"
#import "EncodeTestObject.h"
#import "CopyTestObject.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    return YES;
}
							
- (void)applicationWillResignActive:(UIApplication *)application
{
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
//    //编，解码controller
//    NSData *data = [NSKeyedArchiver archivedDataWithRootObject:self.window.rootViewController];
//    UIViewController *ctr = [NSKeyedUnarchiver unarchiveObjectWithData:data];
//    NSLog(@"tag:%d",ctr.view.tag);
    
    /**
     * 编解码测试
     */
//    EncodeTestObject *to = [[EncodeTestObject alloc]init];
//    to.tag = 1010;
//    
//    //使用下面代码，EncodeTestObject 不申明 nscoding 协议. 会抛异常
//    NSData *td = [NSKeyedArchiver archivedDataWithRootObject:to];
//    EncodeTestObject *ct = [NSKeyedUnarchiver unarchiveObjectWithData:td];
//    NSLog(@"%d",ct.tag);
    
   /**
    * 拷贝测试
    */
//    CopyTestObject *te = [[CopyTestObject alloc]init];
//    CopyTestObject *c = [te copy];//未实现nscopying协议里的copywithzone，会挂
//    CopyTestObject *mc = [te mutableCopy];
//    NSLog(@"%p,%p,%p",te,c,mc);
    
    
    /**
     * @property 的copy 属性发的是copy消息，不是mutable copy
     */
    CopyTestObject *te = [[CopyTestObject alloc]init];
    NSString *str = @"qwe";
    te.str = str;//浅拷

    NSLog(@"%p,%p",str,te.str);//0x48f0,0x48f0
    
    NSMutableString *mstr = [NSMutableString stringWithString:str];//mstr 和str的地址是一样的，说明mstr和str实质是一样的，只是内部做了可变处理
    te.mustr = mstr;//深拷,因为mustr是可变的
    NSLog(@"%p,%p",str,te.mustr);//0x48f0,0xa013830
    
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
